// @ts-ignore
import { request } from '@umijs/max';

/** 获取文章列表 GET /api/knowledge_base/articles */
export async function getArticles(params: any, options?: { [key: string]: any }) {
  return request<API.ReqResult>('/api/knowledge_bases/articles', {
    method: 'GET',
    params,
    ...(options || {}),
  });
}

// 删除文章
export async function delArticle(articleId: any) {
  return request<API.ReqResult>(`/api/knowledge_bases/articles/${articleId}`, {
    method: 'DELETE',
  });
}

// 批量上传文章
export async function articlesBulk(body: any, options?: { [key: string]: any }) {
  return request<API.ReqResult>('/api/knowledge_bases/articles/bulk', {
    method: 'POST',
    headers: {
      'Content-Type': 'application/json',
    },
    data: body,
    ...(options || {}),
  });
}

// 文章详细
export async function getArticlesById(articleId: any) {
  return request<API.ReqResult>(`/api/knowledge_bases/articles/${articleId}`, {
    method: 'GET',
  });
}

// 修改文章问题接口
export async function updArticle(articleId: any, question: any) {
  return request<API.ReqResult>(`/api/knowledge_bases/articles/${articleId}`, {
    method: 'PUT',
    data: { question },
  });
}

// 批量文件上传
export async function fileBatch(knowledgeId: any, file: any) {
  const formData = new FormData();
  formData.append('file', file.originFileObj);
  formData.append('knowledge_base_id', knowledgeId);
  return request<API.ReqResult>(`/api/knowledge_bases/articles/file_batch`, {
    method: 'POST',
    data: formData,
    headers: {
      'Content-Type': 'multipart/form-data',
    },
  });
}

// 语料文件上传
export async function wordBatch(knowledgeId: any, file: any) {
  const formData = new FormData();
  formData.append('file', file.originFileObj);
  formData.append('knowledge_base_id', knowledgeId);
  return request<API.ReqResult>(`/api/knowledge_bases/articles/word_batch`, {
    method: 'POST',
    data: formData,
    headers: {
      'Content-Type': 'multipart/form-data',
    },
  });
}

// 语料入库
export async function wordTakeEffective(body: any) {
  return request<API.ReqResult>(`/api/knowledge_bases/articles/word_take_effective`, {
    method: 'POST',
    data: body,
  });
}
